package br.com.gsc.setup;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.createNiceMock;

import java.io.Serializable;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class AuthenticationHolder implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5089010025591788644L;

	public Authentication getAuthentication() {
		return SecurityContextHolder.getContext().getAuthentication();
	}
	
	public Authentication getTestAuthentication() {
		
		Authentication auth = createNiceMock(Authentication.class);
		
		expect(auth.isAuthenticated()).andReturn(true);
		expect(auth.getName()).andReturn("user").times(2);
		expect(auth.isAuthenticated()).andReturn(false);
		
		replay(auth);
		
		return auth;	
	}
}

